package com.itlong.cloud.config.filelistener;

import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.servlet.MultipartConfigElement;

@Configuration
@Import(DelegatingWebMvcConfiguration.class)
public class MultipartConfiguration extends WebMvcConfigurationSupport {
    // 临时文件地址
//    @Value("${" + PlatformConstants.TMP_FILE_ADDRESS + "}")
    private String fileAddress = "/tmp";

    @Bean(name = "multipartResolver")
    public MultipartResolver multipartResolver()
    {
        return new CustomMultipartResolver();
    }

    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setLocation(fileAddress);
        return factory.createMultipartConfig();
    }
}
